package com.briup.mt.service.impl;

import com.briup.mt.bean.Counsel;
import com.briup.mt.bean.CounselExample;
import com.briup.mt.dao.CounselMapper;
import com.briup.mt.service.ICounselService;
import org.apache.poi.hssf.record.DateWindow1904Record;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class CounselServiceImpl implements ICounselService {

    @Resource
    private CounselMapper counselMapper;

    @Override
    public List<Counsel> query(String question, String status) {
        CounselExample example=new CounselExample();
        if(!StringUtils.isEmpty(question)){
            example.createCriteria().andQuestionLike("%"+question+"%");
        }
        if(!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusLike("%"+status+"%");
        }
        List<Counsel> list = counselMapper.selectByExample(example);
        return list;
    }

    @Override
    public void deleteById(long id) {
        counselMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Counsel counsel) {
        //如果Counsel中没有此id,表示插入; 否则表示更新
        if(counsel.getId() == null){
            //初始化操作
            counsel.setQuestionTime(new Date().getTime());
//            counsel.setReplayTime(new Date().getTime());
            counselMapper.insert(counsel);
        }
        else{
            counsel.setReplayTime(new Date().getTime());
            counselMapper.updateByPrimaryKey(counsel);
        }
//        if(!StringUtils.isEmpty(counsel.getReplay())&&counsel.getStatus()=="未处理"){
//            counsel.setStatus("已处理");
//        }
    }



}
